home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / vc / pro16 / scf2f.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-25  |  14.5 KB  |  474 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include"include\L_Bitmap.h"
  4. #include"include\L_error.h"
  5. #include"include\l_toolap.h"  
  6.  
  7. #define OK 1
  8. #define BAD_COMMAND -2
  9. #define TARGAOLD 1
  10. #define VGA   2
  11.  
  12. #if __BORLANDC__
  13.     extern unsigned _stklen = 13000U;
  14. #endif
  15.  
  16. int format = LEAD, qqfactor = PQ1, palette = NoVGAPalette;
  17.  
  18. main(int argc, char *argv[])
  19. {
  20.   FILEINFO FileInformation;
  21.   struct find_t file;
  22.   int result;
  23.   int i;
  24.   char string[256];
  25.   int mode,page;
  26.   int error;
  27.   char outfile[128], infile[128], pathname[128];
  28.   int wild_flag = 0;
  29.  
  30. #if !defined(FOR_386)
  31.    L_SetCompressFormatJFIFCMP();
  32.    L_SetCompressFormatJTIF();
  33. #endif
  34.  
  35.  L_SetCheckStatus(NO_CHECK);
  36.  if(argc<=2)
  37.   {
  38. #if defined(FOR_386)
  39.       printf("\nDOS32 - File to file software compression utility Version 1.2\n\n");
  40. #else
  41.       printf("\nDOS - File to file software compression utility Version 5.0\n");
  42.       printf("\nThis version has a limit of image width not to exceed 1500 pixels.\n");
  43. #endif
  44.      printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  45.      printf("              8701 Mallard Creek Rd.\n");
  46.      printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  47.      L_SleepKey(2);
  48.      printf("USEAGE: SCF2F <source file> <target file> [/option1] [/option2] \n");
  49.      printf("<source file> is any TARGA, GIF, PCX, 8 or 24 bits TIF, 8 or 24 bits BMP\n");
  50.      printf("<target file> is any DOS file name\n");
  51.      printf("[option1] /LP (LEAD compression with VGA palette.)\n");
  52.      printf("          /L default (LEAD compression without the VGA palette.)\n");
  53.      printf("          /L2JFIF (LEAD JFIF LEAD JPEG Interchange File Format 4:2:2)\n");
  54.      printf("          /L1JFIF (LEAD JFIF LEAD JPEG Interchange File Format 4:1:1)\n");
  55.      printf("          /JFIF (JFIF JPEG Interchange File Format)\n");
  56.      printf("          /L2JTIF (LEAD JTIF JPEG TIF 4:2:2)\n");
  57.      printf("          /L1JTIF (LEAD JTIF JPEG TIF 4:1:1)\n");
  58.      printf("          /JTIF (JTIF JPEG TIF)\n");
  59.      printf("[option2] /# any number from 2 to 255\n");
  60.      printf("          or the following options for LEAD compression only\n");
  61.      printf("          /PQ1  default LEAD Perfect Quality compression option1\n");
  62.      printf("          /PQ2  default LEAD Perfect Quality compression option2\n");
  63.      printf("          /QFS LEAD Quality by far more important than Size\n");
  64.      printf("          /QMS LEAD Quality more important than Size\n");
  65.      printf("          /QS  LEAD Quality and Size are equally Important\n");
  66.      printf("          /SQS LEAD Size more important than Quality sharp\n");
  67.      printf("          /SQT LEAD Size more important than Quality less Tiling\n");
  68.      printf("          /MCQ LEAD Maximum Compression, keep Quality as good as possible\n");
  69.      printf("EXAMPLE   SCF2F *.TGA *.cmp /LP /PQ2    will compress all TGA files to LEAD\n");
  70.      printf("with palette at LEAD Perfect Quality compression option2.\n");
  71.      if(argc==1)
  72.         printf("ERROR NO <source file> and <target file> specified");
  73.      else
  74.         printf("ERROR NO <target file> specified");
  75.      exit(0);
  76.   }
  77.  else
  78.     if(argv[1][0]=='/')
  79.      {
  80.         printf("Error Bad source file %s",argv[1]);
  81.         exit(0);
  82.      }
  83.     else if(argv[2][0]=='/')
  84.      {
  85.         printf("Error Bad source file %s",argv[1]);
  86.         exit(0);
  87.      }
  88.  
  89.  
  90.  strupr(argv[1]);
  91.  strupr(argv[2]);
  92.     
  93.  if ( find_wildletter(argv[1]) == 1)
  94.   {
  95.      if (find_wildletter(argv[2]) == 1)
  96.         wild_flag = 1;
  97.   }
  98.  for (i = 3; i<=argc; i++)
  99.    {
  100.       strupr(argv[i]);
  101.       if(argv[i][0]=='/')
  102.       if(get_value(argv[i]+1)==BAD_COMMAND)
  103.          {
  104.             printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  105.             printf("              8701 Mallard Creek Rd.\n");
  106.             printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  107. #if defined(FOR_386)
  108.       printf("\nDOS32 - File to file software compression utility Version 1.2\n\n");
  109. #else
  110.       printf("\nDOS - File to file software compression utility Version 5.0\n");
  111.       printf("\nThis version has a limit of image width not to exceed 1500 pixels.\n");
  112. #endif
  113.             L_SleepKey(2);
  114.             printf("USEAGE: SCF2F <source file> <target file> [/option1] [/option2] \n");
  115.             printf("<source file> is any TARGA, GIF, PCX, 8 or 24 bits TIF, 8 or 24 bits BMP\n");
  116.             printf("<target file> is any DOS file name\n");
  117.             printf("[option1] /LP (LEAD compression with VGA palette.)\n");
  118.             printf("          /L default (LEAD compression without the VGA palette.)\n");
  119.             printf("          /L2JFIF (LEAD JFIF LEAD JPEG Interchange File Format 4:2:2)\n");
  120.             printf("          /L1JFIF (LEAD JFIF LEAD JPEG Interchange File Format 4:1:1)\n");
  121.             printf("          /JFIF (JFIF JPEG Interchange File Format)\n");
  122.             printf("          /L1JTIF (LEAD JTIF JPEG TIF 4:2:2)\n");
  123.             printf("          /L2JTIF (LEAD JTIF JPEG TIF 4:1:1)\n");
  124.             printf("          /JTIF (JTIF JPEG TIF)\n");
  125.             printf("[option2] /# any number from 2 to 255\n");
  126.             printf("          or the following options for LEAD compression only\n");
  127.             printf("          /PQ1  default LEAD Perfect Quality compression option1\n");
  128.             printf("          /PQ2  default LEAD Perfect Quality compression option2\n");
  129.             printf("          /QFS LEAD Quality by far more important than Size\n");
  130.             printf("          /QMS LEAD Quality more important than Size\n");
  131.             printf("          /QS  LEAD Quality and Size are equally Important\n");
  132.             printf("          /SQS LEAD Size more important than Quality sharp\n");
  133.             printf("          /SQT LEAD Size more important than Quality less Tiling\n");
  134.             printf("          /MCQ LEAD Maximum Compression, keep Quality as good as possible\n");
  135.             printf("          /MC  LEAD Maximum Compression\n");
  136.             printf("EXAMPLE   SCF2F *.TGA *.cmp /LP /PQ2    will compress all TGA files to LEAD\n");
  137.             printf("with palette at LEAD Perfect Quality compression option2.\n");
  138.             printf("\nInvalid option %s",argv[i]);
  139.             exit(0);
  140.          }
  141.    }
  142.    get_pathname(argv[1], pathname);
  143.    result = _dos_findfirst(argv[1], 0 , &file);
  144.    if (result) 
  145.        printf("SCF2F: no such file %s\n",argv[1]);
  146.    else
  147.        while(!result)  /* Stop when _dos_findnext returns */
  148.          {
  149.             strcpy(infile, pathname);
  150.             strcat(infile, file.name);
  151.             if ( (L_FileInfo(infile,&FileInformation)==SUCCESS) && (FileInformation.BitsPerPixel >=8) )
  152.                {
  153.                  if (wild_flag == 1)
  154.                     get_outfilename(file.name, argv[2], outfile);
  155.                  else
  156.                     strcpy(outfile, argv[2]);
  157.                  printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  158.                  printf("              8701 Mallard Creek Rd.\n");
  159.                  printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  160. #if defined(FOR_386)
  161.                  printf("\nDOS32 - File to file software compression utility Version 1.2\n\n");
  162. #else
  163.                  printf("\nDOS - File to file software compression utility Version 5.0\n");
  164.                  printf("\nThis version has a limit of image width not to exceed 1500 pixels.\n");
  165. #endif
  166.                  printf("\nCompressing image file %s to %s\n", infile, outfile);
  167.                  if( FileInformation.Format == FILE_TGA)
  168.                   {
  169.                       error=L_CompressTGA(infile,outfile,format,qqfactor,palette,0);
  170.                   }
  171.                  else if( FileInformation.Format == FILE_TIF)
  172.                   {
  173.                      error=L_CompressTIF(infile,outfile,format,qqfactor,palette);
  174.                   }
  175.                  else if( FileInformation.Format == FILE_BMP)
  176.                   {
  177.                      error=L_CompressBMP(infile,outfile,format,qqfactor,palette);
  178.                   }
  179.                  else if( FileInformation.Format == FILE_OS2)
  180.                   {
  181.                      error=L_CompressBMP(infile,outfile,format,qqfactor,palette);
  182.                   }
  183.                  else if( FileInformation.Format == FILE_PCX)
  184.                   {
  185.                      error=L_CompressPCX(infile,outfile,format,qqfactor,palette);
  186.                   }
  187.                  else if( FileInformation.Format == FILE_GIF)
  188.                   {
  189.                      error=L_CompressGIF(infile,outfile,format,qqfactor,palette);
  190.                   }
  191.                
  192.                  if(error!=SUCCESS)
  193.                   {
  194.                       printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  195.                       printf("              8701 Mallard Creek Rd.\n");
  196.                       printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  197. #if defined(FOR_386)
  198.                       printf("\nDOS32 - File to file software compression utility Version 1.2\n\n");
  199. #else
  200.                       printf("\nDOS - File to file software compression utility Version 5.0\n");
  201.                       printf("\nThis version has a limit of image width not to exceed 1500 pixels.\n");
  202. #endif
  203.                       printf("\nERROR %d COMPRESSING IMAGE FILE %s\n",error,file.name);
  204.                   }
  205.                }
  206.               else
  207.                {
  208.                   printf("\nSCF2F: error opening file %s\n",file.name);
  209.                   putch(7);
  210.                }
  211.             result = _dos_findnext(&file);
  212.          }
  213.  
  214. exit(0);
  215. }
  216.  
  217.  
  218.  
  219.  
  220. get_value(string)
  221. char *string;
  222. {
  223.   char *exttab[20], *extptr1;
  224.   int pathlen1, ret = OK, source;
  225.  
  226.   exttab[0] = "LP";
  227.   exttab[1] = "L";
  228.   exttab[2] = "L2JFIF";
  229.   exttab[3] = "L1JFIF";
  230.   exttab[4] = "JFIF";
  231.   exttab[5] = "L2JTIF";
  232.   exttab[6] = "L1JTIF";
  233.   exttab[7] = "JTIF";
  234.   exttab[8] = "PQ1";
  235.   exttab[9] = "PQ2";
  236.   exttab[10] = "QFS";
  237.   exttab[11] = "QMS";
  238.   exttab[12] = "QS";
  239.   exttab[13] = "SQS";
  240.   exttab[14] = "SQT";
  241.   exttab[15] = "MCQ";
  242.   exttab[16] = "MC";
  243.   exttab[17] = "SAVE";
  244.   exttab[18] = "NOSAVE";
  245.   
  246.   extptr1 = string;
  247.   
  248.   for (source = 0; source < 19; ++source)
  249.    {
  250.       if (!strcmp(extptr1, exttab[source]))
  251.          break;
  252.    }
  253.   
  254.    if (source >= 19)
  255.      {
  256.        qqfactor = atoi(string);
  257.        if (qqfactor <= 0 || qqfactor > 255)
  258.           return(BAD_COMMAND);
  259.        return(OK);
  260.      }
  261.   
  262.     switch (source)
  263.       {
  264.          case  0:
  265.                format = LEAD;
  266.                palette = SaveVGAPalette;
  267.                break;
  268.   
  269.          case  1:
  270.                format = LEAD;
  271.                palette = NoVGAPalette;
  272.                break;
  273.   
  274.          case  2:
  275.                format = LEAD2JFIF;
  276.                qqfactor = 5;
  277.                break;
  278.   
  279.          case  3:
  280.                format = LEAD1JFIF;
  281.                qqfactor = 5;
  282.                break;
  283.  
  284.          case  4:
  285.                format = JFIF;
  286.                qqfactor = 5;
  287.                break;
  288.  
  289.          case  5:
  290.                format = LEAD2JTIF;
  291.                qqfactor = 5;
  292.                break;
  293.   
  294.          case  6:
  295.                format = LEAD1JTIF;
  296.                qqfactor = 5;
  297.                break;
  298.  
  299.          case  7:
  300.                format = JTIF;
  301.                qqfactor = 5;
  302.                break;
  303.  
  304.          case  8:
  305.                qqfactor = PQ1;
  306.                break;
  307.   
  308.          case  9:
  309.                qqfactor = PQ2;
  310.                break;
  311.   
  312.          case  10:
  313.                qqfactor = QFS;
  314.                break;
  315.   
  316.          case  11:
  317.                qqfactor = QMS;
  318.                break;
  319.   
  320.          case  12:
  321.                qqfactor = QS;
  322.                break;
  323.   
  324.          case  13:
  325.                qqfactor = SQS;
  326.                break;
  327.   
  328.          case  14:
  329.                qqfactor = SQT;
  330.                break;
  331.   
  332.   
  333.          case  15:
  334.                qqfactor = MCQ;
  335.                break;
  336.   
  337.          case  16:
  338.                qqfactor = MC;
  339.                break;
  340.   
  341.          case  17:
  342.                palette = SaveVGAPalette;
  343.                break;
  344.   
  345.          case  18:
  346.                palette = NoVGAPalette;
  347.                break;
  348.   
  349.   
  350.         default:
  351.                ret = BAD_COMMAND;
  352.                break;
  353.       }
  354.   
  355.   return(ret);
  356. }
  357.  
  358.  
  359.  
  360.  
  361. get_outfilename(from_file, as_file, to_file)
  362. char from_file[], as_file[], to_file[];
  363. {
  364.   char ext1[120], name1[128], ext2[120], name2[128];
  365.   int i, q, j, ext1_flag = 0, ext2_flag = 0;
  366.   int x, x1;
  367.   
  368.   ext1[0] = 0, ext2[0] = 0, name1[0] = 0, name2[0] = 0;
  369.   for (i = strlen(from_file)-1; i >= 0; i--)
  370.     if (from_file[i] == '.' && from_file[i+1] != '.' && from_file[i-1] != '.')
  371.      {
  372.          ext1_flag = 1;
  373.          break;
  374.       }
  375.   
  376.   strcpy(name1, from_file);
  377.   name1[i] = 0;
  378.   if (ext1_flag == 1)
  379.     strcpy(ext1, from_file+i+1);
  380.   for (i = strlen(as_file)-1; i >= 0; i--)
  381.     if (as_file[i] == '.' && as_file[i+1] != '.' && as_file[i-1] != '.')
  382.      {
  383.         ext2_flag = 1;
  384.         break;
  385.      }
  386.   
  387.   strcpy(name2, as_file);
  388.   name2[i] = 0;
  389.   if (ext2_flag == 1)
  390.      strcpy(ext2, as_file+i+1);
  391.   
  392.   for (i = 0, q = 0; i < strlen(name2); i++)
  393.       {
  394.        if (name2[i] == '*')
  395.            {
  396.            to_file[i] = 0;
  397.            strcat(to_file+i, name1);
  398.            i = i + strlen(name1+q);
  399.            goto exit0;
  400.            }
  401.        if (name2[i] == '?')
  402.           {
  403.           to_file[i] = name1[i];
  404.           q++;
  405.           } 
  406.        else
  407.           to_file[i] = name2[i];
  408.       }
  409.   
  410.    to_file[i] = 0;
  411.    exit0:
  412.   
  413.    to_file[i] = '.';
  414.    i++;
  415.    for (j = 0, q = 0; j < strlen(ext2); i++, j++)
  416.     {
  417.        if (ext2[j] == '*')
  418.         {
  419.            to_file[i] = 0;
  420.            strcat(to_file, ext1+q);
  421.            return(0);
  422.         }
  423.        if (name2[i] == '?')
  424.           {
  425.           to_file[i] = ext1[j];
  426.           q++;
  427.           } 
  428.        else
  429.           to_file[i] = ext2[j];
  430.     }
  431.     to_file[i] = 0;
  432.     if(to_file[i-1] == '.')
  433.        to_file[i-1] = 0;
  434.   
  435.   return(0);
  436. }
  437.   
  438.  
  439.  
  440.   
  441. find_wildletter(string)
  442. char string[];
  443. {
  444.   int i;
  445.   
  446.   for (i = 0; i < strlen(string); i++)
  447.    if (string[i] == '*')
  448.          return(1);
  449.   
  450.   return(0);
  451. }
  452.  
  453.  
  454. get_pathname(in, pathname)
  455. char in[], pathname[];
  456. {
  457.   int i;
  458.  
  459.   strcpy(pathname, in);
  460.   for (i = strlen(in)-1; i >= 0; i--)
  461.     {
  462.        if (in[i] == '\\' || in[i] == ':')
  463.           break;
  464.     }
  465.  
  466.   if (i == 0)
  467.      pathname[0] = 0;
  468.   else
  469.      pathname[i+1] = 0;
  470. }
  471.  
  472.  
  473.  
  474.